<template>
  <el-dialog title="隧道基础信息录入" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">
    <el-form :model="tunnelInfo" label-width="100px" class="demo-form-inline">
      <el-row>
        <el-col :span="12">
          <el-form-item label="隧道名称">
            <el-input v-model="tunnelInfo.tunName"></el-input>
          </el-form-item></el-col>
        <el-col :span="12">
          <el-form-item label="隧道类型">
            <el-select v-model="tunnelInfo.tunType" placeholder="请选择类型">
              <el-option label="分离式隧道" value="分离式隧道"></el-option>
              <el-option label="小净距隧道" value="小净距隧道"></el-option>
              <el-option label="分岔隧道" value="分岔隧道"></el-option>
              <el-option label="连拱隧道" value="连拱隧道"></el-option>
            </el-select>
          </el-form-item></el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="建设单位">
            <el-input v-model="tunnelInfo.tunDevelopunit"></el-input>
          </el-form-item></el-col>
        <el-col :span="12">
          <el-form-item label="施工单位">
            <el-input v-model="tunnelInfo.tunConstructunit"></el-input>
          </el-form-item></el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="设计单位">
            <el-input v-model="tunnelInfo.tunDesignunit"></el-input>
          </el-form-item></el-col>
        <el-col :span="12">
          <el-form-item label="监理单位">
            <el-input v-model="tunnelInfo.tunSupervisionunit"></el-input>
          </el-form-item></el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="创建时间">
            <el-date-picker type="date" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期"
              v-model="tunnelInfo.createTime"></el-date-picker>
          </el-form-item></el-col>
        <el-col :span="12"></el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="create">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import api from '../../../api'
import qs from 'qs'
export default {
  data() {
    return {
      dialogVisible: false,
      //项目信息
      proAdminList: [],
      ctype: [],
      tunnelInfo: {
        proId: '',
        tunCode: '',
        tunName: '',
        tunStartMileagePrefix: '',
        tunEndMileagePrefix: '',
        tunDevelopunit: '',
        tunConstructunit: '',
        tunDesignunit: '',
        tunSupervisionunit: '',
        createTime: '',
        operation: '',
        tunType: ''
      }
    }
  },
  mounted() {
    this.$bus.$on('onAddTunnelInfoShow', (flag) => {
      console.log(this.tunnelInfo.proId)
      if (this.tunnelInfo.proId == '') {
        this.$message({
          type: 'fail',
          message: '请选择项目'
        })
        this.dialogVisible = false
      } else {
        this.dialogVisible = flag
      }
    })
    this.$bus.$on('onAddTunnelInfoproid', (flag) => {
      this.tunnelInfo.proId = flag
    })
  },
  methods: {
    // 查询施工方式
    shigong() {
      api
        .proAdminfindByAll()
        .then((res) => {
          if (res.data.code == 2001) {
            this.proAdminList = res.data.data
            console.log(res.data)
          }
        })
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done()
        })
        .catch((_) => { })
    },
    create() {
      // 查询施工方式
      api
        .tunnelInfoSave(qs.stringify(this.tunnelInfo))
        .then((res) => {
          if (res.data.code == 2001) {
            this.$message({
              type: 'success',
              message: '添加成功!'
            })
            this.dialogVisible = false
            this.$bus.$emit('onRefreshTunnelInfo', this.tunnelInfo.proId)
          }
        })
    }
  }
}
</script>

<style>

</style>